<template>
  <!-- 方案规划导航栏 -->
   <div style="width: 100%;height: 100%;text-align: center;">

  
    <div id="elePriceDiv" style="display: flex;margin-top: 1vh;" class="box">
 
      <el-form :inline="true" :model="formInline" style="margin-left: 2vh;margin-top: 1vh;width: 19%;" class="demo-form-inline">
        <el-form-item label="电价:">

          <el-radio-group @change="elecPriceChange" v-model="form.elecPriceType"> 
            <el-radio label="fixedElecPrice">固定电价</el-radio>
            <el-radio label="variableElecPrice">峰⾕电价</el-radio>
          </el-radio-group>

        </el-form-item>
      
      </el-form>

      <el-form v-if="this.form.elecPriceType=='fixedElecPrice'" :inline="true" :model="formInline" style="margin-left: 2vh;margin-top: 1vh;    width: 74%;float: left;text-align: left;" class="demo-form-inline">
        <el-form-item label="固定电价:">
          <el-input style="width: 90%;margin-top: 0vh;" v-model="form.fixedElecPrice">
              <template slot="append">元/kWh</template>
            </el-input>
        </el-form-item>
      
      </el-form>

      
      <el-form v-if="this.form.elecPriceType=='variableElecPrice'" :inline="true" :model="formInline" style="margin-left: 2vh;margin-top: -2vh;width: 91%;float: left;" class="demo-form-inline">
        <el-row gutter="20"> 
          <el-form-item label="峰时电价:">
            <el-input style="width: 90%;margin-top: 0vh;" v-model="form.peakHourElecPrice">
                <template slot="append">元/kWh</template>
              </el-input>
          </el-form-item>
          <el-form-item label="峰时段:">
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.peakHourStart"></el-input>
            </el-col>
            <el-col :span="2">
              <span style="color: #f2f2f2;">~</span>
            </el-col>
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.peakHourEnd"></el-input>
            </el-col>
          </el-form-item>
        </el-row>

        <el-row gutter="20"> 
          <el-form-item label="⾕时电价:">
            <el-input style="width: 90%;margin-top: 0vh;" v-model="form.hourlyHourElecPrice">
                <template slot="append">元/kWh</template>
              </el-input>
          </el-form-item>
          <el-form-item label="⾕时段:">
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.hourlyHourStart"></el-input>
            </el-col>
            <el-col :span="2">
              <span style="color: #f2f2f2;">~</span>
            </el-col>
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.hourlyHourEnd"></el-input>
            </el-col>
          </el-form-item>
        </el-row>
        
        <el-row gutter="20"> 
          <el-form-item label="平时电价:">
            <el-input style="width: 90%;margin-top: 0vh;" v-model="form.regularHourElecPrice">
                <template slot="append">元/kWh</template>
              </el-input>
          </el-form-item>
          <el-form-item label="平时段:">
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.regularHourStart"></el-input>
            </el-col>
            <el-col :span="2">
              <span style="color: #f2f2f2;">~</span>
            </el-col>
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.regularHourEnd"></el-input>
            </el-col>
          </el-form-item>
        </el-row>

             
        <el-row gutter="20"> 
          <el-form-item label="尖时电价:">
            <el-input style="width: 90%;margin-top: 0vh;" v-model="form.sharpHourElecPrice">
                <template slot="append">元/kWh</template>
              </el-input>
          </el-form-item>
          <el-form-item label="尖时段:">
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.sharpHourStart"></el-input>
            </el-col>
            <el-col :span="2">
              <span style="color: #f2f2f2;">~</span>
            </el-col>
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.sharpHourEnd"></el-input>
            </el-col>
          </el-form-item>
        </el-row>
      
      </el-form>


      <div id="buttonDiv" style="margin-top: 0.7vh;width: 17%;">
        <el-button type="primary" @click="uploadData()" style="width: 110px">
          <span class="button-text">上传</span>
        </el-button>
            
        <el-button type="primary" @click="savePageData()" style="width: 110px">
            <span class="button-text">保存</span>
        </el-button>

      </div>

       
   
    
    </div>
 
 
  
  <div id="box2DIv" class="box2">
 
    <el-form :inline="true" :model="formInline" style="margin-left: 2vh;margin-top: 1vh;    width: 74%;float: left;text-align: left;" class="demo-form-inline">
        <el-form-item label="折现率:">
          <el-input style="width: 90%;margin-top: 0vh;" v-model="form.discountRate">
              <template slot="append">%</template>
            </el-input>
        </el-form-item>

        <el-form-item label="水价:">
          <el-input style="width: 90%;margin-top: 0vh;" v-model="form.waterPrice">
              <template slot="append">元/t</template>
            </el-input>
        </el-form-item>
        
        <el-form-item label="售氢价格:">
            <el-input style="width: 90%;margin-top: 0vh;" v-model="form.hydrogenSalesPrice">
              <template slot="append">元/kg</template>
            </el-input>
        </el-form-item>

      </el-form>

  </div>
  
  
        
  <!-- 上传弹窗 -->
  <div>
    <el-dialog :title="dialogTitle" :visible.sync="dialogShowFlag"  width="80vh" align="left">
      
      <div class="uploadModal">
        
        <div class="modal-body">
          
          <el-link style="color: #2e44ff;font-size: 1vw;" @click="downloadTemp()" class="modal-description">下载模版，填写信息</el-link>
          <button class="upload-area">
            <span class="upload-area-icon">
              <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="340.531" height="419.116" viewBox="0 0 340.531 419.116">
                <g id="files-new" clip-path="url(#clip-files-new)">
                  <path id="Union_2" data-name="Union 2" d="M-2904.708-8.885A39.292,39.292,0,0,1-2944-48.177V-388.708A39.292,39.292,0,0,1-2904.708-428h209.558a13.1,13.1,0,0,1,9.3,3.8l78.584,78.584a13.1,13.1,0,0,1,3.8,9.3V-48.177a39.292,39.292,0,0,1-39.292,39.292Zm-13.1-379.823V-48.177a13.1,13.1,0,0,0,13.1,13.1h261.947a13.1,13.1,0,0,0,13.1-13.1V-323.221h-52.39a26.2,26.2,0,0,1-26.194-26.195v-52.39h-196.46A13.1,13.1,0,0,0-2917.805-388.708Zm146.5,241.621a14.269,14.269,0,0,1-7.883-12.758v-19.113h-68.841c-7.869,0-7.87-47.619,0-47.619h68.842v-18.8a14.271,14.271,0,0,1,7.882-12.758,14.239,14.239,0,0,1,14.925,1.354l57.019,42.764c.242.185.328.485.555.671a13.9,13.9,0,0,1,2.751,3.292,14.57,14.57,0,0,1,.984,1.454,14.114,14.114,0,0,1,1.411,5.987,14.006,14.006,0,0,1-1.411,5.973,14.653,14.653,0,0,1-.984,1.468,13.9,13.9,0,0,1-2.751,3.293c-.228.2-.313.485-.555.671l-57.019,42.764a14.26,14.26,0,0,1-8.558,2.847A14.326,14.326,0,0,1-2771.3-147.087Z" transform="translate(2944 428)" fill="var(--c-action-primary)"/>
                </g>
              </svg>
            </span>
            <span class="upload-area-title">请选择您要上传的文件，仅支持xls,xlsx格式文件</span>
            <span class="upload-area-description">
              <br/><strong @click="goFile()">点击上传</strong>
            </span>
          </button>
        </div>
        <form style="display: none;" enctype="multipart/form-data">
            <input type="file" id="file" name="file" ref="files" @change="importData($event)"
                accept=".xls,.xlsx" />
        </form>
        <div class="modal-footer">
          <!-- <el-button type="primary" @click="confirmUpload()">确认上传</el-button> -->
          <el-button type="primary" @click="closeWindow()">取消</el-button>
        </div>
      </div>

 
    </el-dialog>
  </div>
  <!-- 上传弹窗 -->

</div>
  
</template>

<script>
 

  export default {
    name: 'resourceParameters',
    data() {
      return {
        form: {
          id: '',
          projectId: '',
          type: 'hp',
          elecPriceType: 'fixedElecPrice',
          fixedElecPrice: '',
          peakHourElecPrice: '',
          peakHourStart: '',
          peakHourEnd: '',
          hourlyHourElecPrice: '',
          hourlyHourStart: '',
          hourlyHourEnd: '',
          regularHourElecPrice: '',
          regularHourStart: '',
          regularHourEnd: '',

          sharpHourElecPrice: '',
          sharpHourStart: '',
          sharpHourEnd: '',
          discountRate: '',
          waterPrice: '',
          hydrogenSalesPrice: '',
        },
        activeDate: '',
        type: '', 
        dialogTitle : "上传峰谷电价数据",
        dialogShowFlag : false,
        templateName : "elecPriceTemplate.xlsx",
        uploadUrl : "/iepsapi/ea/hpEconomicAnalysis/importElecPriceData",
        projectId : ""
      }
    },
    mounted: function() {
      //获取项目id
      this.projectId = this.$route.query.projectId;
      this.form.projectId = this.projectId;
      this.queryPageData();
    },
    methods: {

      
      uploadData : function(){
        this.dialogShowFlag = true;
      },

      closeWindow : function(){
        this.dialogShowFlag = false;
      },

      goFile() {
          this.$refs.files.click();
      },
      downloadTemp: function () { 
          window.open('/iepsapi/ea/hpEconomicAnalysis/downloadTemp?templateName=' + this.templateName, '_self');
      },
      
      //导入
      importData: function (file) {
          var vm = this;
          var files = file.target.files[0];
          var fileName = files.name;
          if (!files) {
              return;
          }
          if (files.type === "application/vnd.ms-excel" || files.type === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
              var formData = new FormData();
              formData.append('file', file.target.files[0]);
              formData.append('fileName', fileName);
              formData.append('type', vm.form.type);
              formData.append('tableName', "resource_parameters");
              formData.append('id', vm.form.id);
              const loading = this.$loading({
                  lock: true,
                  text: "正在导入...",
                  spinner: "hy-icon-loading",
                  background: "rgba(0, 0, 0, 0.7)",
              });
              $.ajax({
                  type: 'post',
                  url: vm.uploadUrl,
                  data: formData,
                  cache: false,
                  processData: false,
                  contentType: false,
                  timeout: 300000, // 设置超时时间为300000毫秒（即5分钟） 
                  success: function (res) {
                      //成功执行的代码
                      loading.close();
                      var state = res.state;
                      if (state == 'error') {
                
                          vm.$message({
                            message: res.message,
                            type: 'info'
                          });
                      } else {
                  
                          vm.$message({
                            message: '导入成功',
                            type: 'success'
                          });

                          vm.dialogShowFlag = false;
                      }
                      setTimeout(() => {
                          vm.queryPageData();;
                      }, 1000);



                  },
                  error: function (xhr, textStatus, errorThrown) {
                      loading.close();
                      // 处理超时错误
                      if (textStatus == 'timeout') {
                          // 超时后的处理逻辑
                          vm.$message({
                            message: '后台导入中',
                            type: 'info'
                          });
                      } else {
                          vm.$message({
                            message: '导入失败',
                            type: 'error'
                          });
                      }
                  }
              })
          } else {
              this.$message({
                  message: '文件格式错误！',
                  type: 'error'
              });
              return;
          }
      },


      queryPageData : function(){

        var vm = this;

        this.$http.post('/iepsapi/ea/hpEconomicAnalysis/queryPageData?projectId='+this.projectId+"&tableName=resource_parameters").then((res) => {
          var result = res.data.data;
          if(result){
            vm.form = result;

              
            if(vm.form.elecPriceType=="fixedElecPrice"){
              $("#elePriceDiv").attr("style","display: flex;margin-top: 1vh;height:6vh");
              $("#box2DIv").attr("style","top: 17.5vh;");
              $("#buttonDiv").attr("style","margin-top: 0.7vh;width: 17%;");
            }else if(vm.form.elecPriceType=="variableElecPrice"){
              $("#elePriceDiv").attr("style","display: block;margin-top: 1vh;height:30vh");
              $("#box2DIv").attr("style","top: 41vh;");
              $("#buttonDiv").attr("style","margin-top: 17.7vh;float: right;width: 95%;position: absolute;text-align: right;");
            }

          }
        }).catch((error) => {
          console.log(error);
        });


      },
      savePageData : function(){
 
        var vm = this;
        this.$http.post('/iepsapi/ea/hpEconomicAnalysis/savePageData', {
          "pageData": JSON.stringify(this.form),
          "tableName":"resource_parameters"
        }).then((res) => {
        
          if (res.data.flag) {
            vm.form.id = res.data.id;
            this.$message({
              type: 'success',
              message: res.data.message
            });

          } else {
            this.$message.error(res.data.message);
          }
        });

      },

      elecPriceChange : function(){

        if(this.form.elecPriceType=="fixedElecPrice"){
          $("#elePriceDiv").attr("style","display: flex;margin-top: 1vh;height:6vh");
          $("#box2DIv").attr("style","top: 17.5vh;");
          $("#buttonDiv").attr("style","margin-top: 0.7vh;width: 17%;");
        }else if(this.form.elecPriceType=="variableElecPrice"){
          $("#elePriceDiv").attr("style","display: block;margin-top: 1vh;height:30vh");
          $("#box2DIv").attr("style","top: 41vh;");
          $("#buttonDiv").attr("style","margin-top: 17.7vh;float: right;width: 95%;position: absolute;text-align: right;");
        }

      },

      buttonClick : function(type,divId){
        for(var i = 1;i<=6;i++){
          $("#hpDiv"+i).css("background","#1f2c6c3b");
        }
        $("#"+divId).css("background","#409EFF");
        this.activeDate = new Date().getTime();
        //路由跳转
        //this.$router.push('/'+type)
      }, 
       
    }
  }
</script>



<style>

.el-table{
  background-color: rgb(20 34 78);
  color: #FFFFFF;
  border-color: rgb(24 63 124 / 51%);
  *{
    border-color: rgb(24 63 124 / 51%) !important;
  }
  .el-table__header-wrapper{
    tr{
      background-color: rgb(10 24 90 / 81%);
      th{
        color: #ffffff;
        background-color: rgba(0,0,0,0.4);
      }
    }
  }
  .el-table__body-wrapper{
    tr{
      background-color: rgb(8 26 80 / 88%);
      &:hover>td{      
        background-color: rgb(13 30 80);
      }
    }
  }
}
  .el-form--inline .el-form-item__content {
      display: inline-block;
      vertical-align: middle;
      margin-left: 1vh;
  }

  .el-radio {
      color: #eff4ff;
      cursor: pointer;
      margin-right: 30px;
  }

  .el-form-item {
      margin-bottom: 5px;
  }
  .el-form-item__label {
      text-align: right;
      vertical-align: middle;
      float: left;
      font-size: 14px;
      color: #f2f2f2;
      line-height: 40px;
      padding: 0 1px 0 0;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
  }
  .el-input__inner { 
      background-color: #202b6180;
      background-image: none;
      border-radius: 4px;
      border: 1px solid #5c7bc5;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      color: #a3aec5;
      display: inline-block;
      font-size: inherit;
      height: 40px;
      line-height: 40px;
      outline: 0;
      padding: 0 15px;
      -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
      transition: border-color .2s cubic-bezier(.645,.045,.355,1);
      width: 100%;
  }

  .el-input-group__append, .el-input-group__prepend {
    background-color: #305997;
    color: #ffffff;
    vertical-align: middle;
    display: table-cell;
    position: relative;
    border: 1px solid #506aa7;
    border-radius: 4px;
    padding: 0 20px;
    width: 1px;
    white-space: nowrap;
  }
</style>


<style scoped> 

  /* 设定地图的大小 */
  #allmap{
    height: 350px;
    width: 100%;
  }

  .buttonStyle {
    height: 4vh;
    width: 27vh;
    display: inline-block;
    -webkit-border-radius: 60px;
    -moz-border-radius: 60px;
    cursor: pointer;
    border-radius: 10px;
    font-family: Arial;
    border: none;
    color: #ffffff;
    font-size: 1.6vh;
    background: #1f2c6c3b;
    border-bottom: 1px solid rgb(64, 158, 255);
    margin: 1.5vh 10px;
    text-align: center;
    line-height: 4vh;
    vertical-align: middle;
    text-decoration: none;
  }

  .box{ 
    width: 98%;
    height: 6vh;
    margin: auto;
    border-radius: 5px;
    margin: auto;
    background: #202b614f;
    border: 1px solid rgb(62 111 219 / 88%);
  }

  .box1{ 
    width: 96%;
    height: 30vh;
    margin-top: 1vh;
    margin: 0 auto;
    top: 18vh;
    left: 3.5vh;
    position: absolute;
    border-radius: 5px;
    margin: auto;
    background: #202b614f;
    border: 1px solid rgb(62 111 219 / 88%);
  }

  .box2{ 
    width: 96%;
    height: 7vh;
    margin-top: 1vh;
    margin: 0 auto;
    top: 17.5vh;
    left: 3.5vh;
    position: absolute;
    border-radius: 5px; 
    background: #202b614f;
    border: 1px solid rgb(62 111 219 / 88%);
  }

  .titleCss{
    font-size: 22px;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.2;
    color: #f2f2f2;
  }
</style>
